/*
 * JsonrpcProcessor.h
 *
 *  Created on: Apr 18, 2017
 *      Author: zhangjf
 */

#ifndef SRC_JSONRPCPROCESSOR_H_
#define SRC_JSONRPCPROCESSOR_H_

#include <Poco/JSON/Object.h>
#include <Poco/AutoPtr.h>
#include <Poco/BasicEvent.h>
#include <Poco/Dynamic/Var.h>

using namespace Poco;
using namespace Poco::JSON;
using namespace Poco::Dynamic;

namespace util
{

struct JsonrpcParams
{
	std::string strVer;
	std::string strMethod;
	Object::Ptr joParams;
	std::string strSid;
	bool blNotif = false;
	int id = -1;

	bool blRet;
	Object joResult;
};

class JsonrpcProcessor
{
public:
	JsonrpcProcessor();
	virtual ~JsonrpcProcessor();

	bool process(const std::string& strReq, Object& strResp, bool& blNotif);

	BasicEvent<JsonrpcParams> doCheckParams;
	BasicEvent<JsonrpcParams> doRunJsonrpcMethod;
private:
	bool parseJsonrpc(const std::string& strReq, JsonrpcParams& params);
	bool checkParams(JsonrpcParams& params);
};

} // endof namespace util

#endif /* SRC_JSONRPCPROCESSOR_H_ */
